home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / bfd / host-aout.c < prev    next >
C/C++ Source or Header  |  1992-09-11  |  9KB  |  268 lines

  1. /* BFD backend for local host's a.out binaries
  2.    Copyright (C) 1990-1991 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.  Probably John Gilmore's fault.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "bfd.h"
  22. #include "sysdep.h"
  23. #include "libbfd.h"
  24.  
  25. #define    ARCH_SIZE    32
  26.  
  27. #include "libaout.h"           /* BFD a.out internal data structures */
  28. #include "aout64.h"
  29.  
  30. /* If the host has short headers on ZMAGIC files (like SunOS), then the
  31.    text segment offset is 0 (as specified in aout64.h).  If it doesn't
  32.    have short headers, the text segment offset is PAGE_SIZE.  */
  33. #ifndef    HOST_SHORT_HEADER_HACK
  34. #undef N_TXTOFF
  35. #define N_TXTOFF(x)   ( (N_MAGIC((x)) == ZMAGIC) ? PAGE_SIZE : EXEC_BYTES_SIZE)
  36. #endif
  37.  
  38. /* When porting to a new system, you must supply:
  39.  
  40.     HOST_PAGE_SIZE
  41.     HOST_SEGMENT_SIZE    (optional -- defaults to page size)
  42.     HOST_MACHINE_ARCH    (optional)
  43.     HOST_MACHINE_MACHINE    (optional)
  44.     HOST_TEXT_START_ADDR
  45.     HOST_STACK_END_ADDR
  46.     HOST_SHORT_HEADER_HACK    (optional)
  47.  
  48.    in the ./hosts/h-systemname.h file.  */
  49.  
  50. #define    PAGE_SIZE    HOST_PAGE_SIZE
  51. #ifdef HOST_SEGMENT_SIZE
  52. #define    SEGMENT_SIZE    HOST_SEGMENT_SIZE
  53. #else
  54. #define    SEGMENT_SIZE    HOST_PAGE_SIZE
  55. #endif
  56. #define    TEXT_START_ADDR    HOST_TEXT_START_ADDR
  57. #define    STACK_END_ADDR    HOST_STACK_END_ADDR
  58.  
  59. static bfd_target *NAME(host_aout,callback) ();
  60.  
  61. /*SUPPRESS558*/
  62. /*SUPPRESS529*/
  63.  
  64. bfd_target *
  65. DEFUN(NAME(host_aout,object_p), (abfd),
  66.      bfd *abfd)
  67. {
  68.   struct external_exec exec_bytes;
  69.   struct internal_exec exec;
  70.  
  71.   if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
  72.       != EXEC_BYTES_SIZE) {
  73.     bfd_error = wrong_format;
  74.     return 0;
  75.   }
  76.  
  77.   exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
  78.  
  79.   if (N_BADMAG (exec)) return 0;
  80.  
  81.   NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
  82.   return NAME(aout,some_aout_object_p) (abfd, &exec, NAME(host_aout,callback));
  83. }
  84.  
  85. /* Set parameters about this a.out file that are machine-dependent.
  86.    This routine is called from NAME(some_aout_object_p) just before it returns.
  87.    This routine moves any data from the exec header,
  88.    which is needed by the BFD code, out to places known to BFD.  This
  89.    allows the rest of the BFD code to not know or care about the structure
  90.    of exec_hdr (abfd).  */
  91.  
  92. static bfd_target *
  93. DEFUN(NAME(host_aout,callback), (abfd),
  94.      bfd *abfd)
  95. {
  96.   struct internal_exec *execp = exec_hdr (abfd);
  97.  
  98.   adata(abfd)->page_size = PAGE_SIZE;
  99.   adata(abfd)->segment_size = SEGMENT_SIZE;
  100.   adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
  101.  
  102. #ifdef HOST_MACHINE_ARCH
  103.   bfd_default_set_arch_mach(abfd,
  104.                 HOST_MACHINE_ARCH, 
  105. #ifdef HOST_MACHINE_MACHINE
  106.                   HOST_MACHINE_MACHINE
  107. #else  /* not HOST_MACHINE_MACHINE */
  108.                 0
  109. #endif /* not HOST_MACHINE_MACHINE */
  110.                  );
  111. #endif /* HOST_MACHINE_ARCH */
  112.  
  113.   WORK_OUT_FILE_POSITIONS (abfd, execp);
  114.  
  115.   return abfd->xvec;
  116. }
  117.  
  118.  
  119. boolean
  120. DEFUN(NAME(host_aout,mkobject), (abfd),
  121.      bfd *abfd)
  122. {
  123.   /* This struct is just for allocating two things with one zalloc, so
  124.      they will be freed together, without violating alignment constraints. */
  125.   struct aout_exec {
  126.     struct aoutdata    aoutdata;
  127.     struct internal_exec    exec;
  128.   } *rawptr;
  129.  
  130.   bfd_error = system_call_error;
  131.  
  132.   /* Use an intermediate variable for clarity */
  133.   rawptr = (struct aout_exec *)bfd_zalloc (abfd, sizeof (struct aout_exec));
  134.  
  135.   if (rawptr == NULL) {
  136.     bfd_error = no_memory;
  137.     return false;
  138.   }
  139.  
  140.   set_tdata (abfd, &rawptr->aoutdata);
  141.   exec_hdr (abfd) = &rawptr->exec;
  142.  
  143.   /* For simplicity's sake we just make all the sections right here. */
  144.  
  145.   obj_textsec (abfd) = (asection *)NULL;
  146.   obj_datasec (abfd) = (asection *)NULL;
  147.   obj_bsssec (abfd) = (asection *)NULL;
  148.   bfd_make_section (abfd, ".text");
  149.   bfd_make_section (abfd, ".data");
  150.   bfd_make_section (abfd, ".bss");
  151.  
  152.   adata(abfd)->page_size = PAGE_SIZE;
  153.   adata(abfd)->page_size = SEGMENT_SIZE;
  154.   adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
  155.  
  156.   return true;
  157. }
  158.  
  159. /* Write an object file in host a.out format.
  160.    Section contents have already been written.  We write the
  161.    file header, symbols, and relocation.  */
  162.  
  163. boolean
  164. DEFUN(NAME(host_aout,write_object_contents), (abfd),
  165.      bfd *abfd)
  166. {
  167.   size_t data_pad = 0;
  168.   struct external_exec exec_bytes;
  169.   struct internal_exec *execp = exec_hdr (abfd);
  170.  
  171.   execp->a_text = obj_textsec (abfd)->size;
  172.  
  173.   WRITE_HEADERS (abfd, execp);
  174.   return true;
  175. }
  176.  
  177. /* We use BFD generic archive files.  */
  178. #define    aout_32_openr_next_archived_file    bfd_generic_openr_next_archived_file
  179. #define    aout_32_generic_stat_arch_elt        bfd_generic_stat_arch_elt
  180. #define    aout_32_slurp_armap            bfd_false
  181. #define    aout_32_slurp_extended_name_table    bfd_true
  182. #define    aout_32_write_armap            (PROTO (boolean, (*),    \
  183.      (bfd *arch, unsigned int elength, struct orl *map, int orl_count,    \
  184.       int stridx))) bfd_false
  185. #define    aout_32_truncate_arname            bfd_dont_truncate_arname
  186.  
  187. /* No core file defined here -- configure in trad-core.c separately.  */
  188. #define    aout_32_core_file_failing_command _bfd_dummy_core_file_failing_command
  189. #define    aout_32_core_file_failing_signal _bfd_dummy_core_file_failing_signal
  190. #define    aout_32_core_file_matches_executable_p    \
  191.                 _bfd_dummy_core_file_matches_executable_p
  192.  
  193. #define aout_32_bfd_debug_info_start        bfd_void
  194. #define aout_32_bfd_debug_info_end        bfd_void
  195. #define aout_32_bfd_debug_info_accumulate    (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
  196.  
  197. #define    aout_64_openr_next_archived_file    aout_32_openr_next_archived_file
  198. #define    aout_64_generic_stat_arch_elt        aout_32_generic_stat_arch_elt
  199. #define    aout_64_slurp_armap            aout_32_slurp_armap
  200. #define    aout_64_slurp_extended_name_table    aout_32_slurp_extended_name_table
  201. #define    aout_64_write_armap            aout_32_write_armap
  202. #define    aout_64_truncate_arname            aout_32_truncate_arname
  203.  
  204. #define    aout_64_core_file_failing_command     aout_32_core_file_failing_command
  205. #define    aout_64_core_file_failing_signal    aout_32_core_file_failing_signal
  206. #define    aout_64_core_file_matches_executable_p    aout_32_core_file_matches_executable_p
  207.  
  208. #define aout_64_bfd_debug_info_start        aout_32_bfd_debug_info_start
  209. #define aout_64_bfd_debug_info_end        aout_32_bfd_debug_info_end
  210. #define aout_64_bfd_debug_info_accumulate    aout_32_bfd_debug_info_accumulate
  211.  
  212.  
  213. /* We implement these routines ourselves, rather than using the generic
  214.    a.out versions.  */
  215. #define    aout_write_object_contents    host_write_object_contents
  216.  
  217. bfd_target host_aout_big_vec =
  218.   {
  219.     "a.out-host-big",
  220.     bfd_target_aout_flavour,
  221.     true,            /* target byte order */
  222.     true,            /* target headers byte order */
  223.     (HAS_RELOC | EXEC_P |    /* object flags */
  224.      HAS_LINENO | HAS_DEBUG |
  225.      HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
  226.     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  227.     ' ',                           /* ar_pad_char */
  228.     16,                               /* ar_max_namelen */
  229.     3,                               /* minimum alignment power */
  230.     _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
  231.     _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
  232.     
  233.       {_bfd_dummy_target, NAME(host_aout,object_p),
  234.        bfd_generic_archive_p, _bfd_dummy_target},
  235.       {bfd_false, NAME(host_aout,mkobject),
  236.        _bfd_generic_mkarchive, bfd_false},
  237.       {bfd_false, NAME(host_aout,write_object_contents), /* bfd_write_contents */
  238.        _bfd_write_archive_contents, bfd_false},
  239.     
  240.     JUMP_TABLE(JNAME(aout))
  241. };
  242.  
  243. bfd_target host_aout_little_vec =
  244.   {
  245.     "a.out-host-little",
  246.     bfd_target_aout_flavour,
  247.     false,            /* target byte order */
  248.     false,            /* target headers byte order */
  249.     (HAS_RELOC | EXEC_P |    /* object flags */
  250.      HAS_LINENO | HAS_DEBUG |
  251.      HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
  252.     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  253.     ' ',                           /* ar_pad_char */
  254.     16,                               /* ar_max_namelen */
  255.     3,                               /* minimum alignment power */
  256.     _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putb16, /* data */
  257.     _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
  258.     
  259.       {_bfd_dummy_target, NAME(host_aout,object_p),
  260.        bfd_generic_archive_p, _bfd_dummy_target},
  261.       {bfd_false, NAME(host_aout,mkobject),
  262.        _bfd_generic_mkarchive, bfd_false},
  263.       {bfd_false, NAME(host_aout,write_object_contents), /* bfd_write_contents */
  264.        _bfd_write_archive_contents, bfd_false},
  265.     
  266.     JUMP_TABLE(JNAME(aout))
  267. };
  268.